//package com.zhz.mall.portal.utils;
//
//import com.zhz.mall.common.exception.BusinessException;
//import com.zhz.mall.portal.contant.UserErrorCode;
//import com.zhz.mall.portal.domain.MemberDetails;
//import org.springframework.security.authentication.UsernamePasswordAuthenticationToken;
//import org.springframework.security.core.Authentication;
//import org.springframework.security.core.context.SecurityContextHolder;
//import org.springframework.security.core.userdetails.UserDetails;
//
//import java.util.Objects;
//
///**
// * @author zhouhengzhe
// * @date 2023/2/4
// */
//public class UserUtil {
//
//    /**
//     * 获取权限信息
//     *
//     * @return
//     */
//    public static MemberDetails getMemberDetailsInfo() {
//        Authentication authentication = SecurityContextHolder.getContext().getAuthentication();
//        MemberDetails memberDetails = (MemberDetails) authentication.getPrincipal();
//        if (Objects.isNull(memberDetails)) {
//            throw new BusinessException(UserErrorCode.LOGIN_FAIL);
//        }
//        return memberDetails;
//    }
//
//    /**
//     * 设置权限信息
//     *
//     * @param userDetails
//     */
//    public static void setMemberDetailsInfo(UserDetails userDetails) {
//        // 生成springsecurity的通过认证标识
//        UsernamePasswordAuthenticationToken authenticationToken =
//                new UsernamePasswordAuthenticationToken(userDetails, null, userDetails.getAuthorities());
//        SecurityContextHolder.getContext().setAuthentication(authenticationToken);
//    }
//
//}
